﻿using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using MySql.Data.MySqlClient;

/// <summary>
/// Descripción breve de LineadefarmaciaDA
/// </summary>
public static class LineadefarmaciaDA
{
    public static string nuevalineaordfarmacia(string lineaordfarmaciaid, string ordfarmaciaid, string lineaordfarmaciadesc, string lineaordfarmaciacant, string medicamentoid)
    {   //inserta una nueva linea de orden de farmacia 

        MySqlConnection conexion = Conexion.obtConexion();
        string consulta = @"INSERT INTO lineasordfarmacia
                            values (" + lineaordfarmaciaid + "," + ordfarmaciaid + "," + lineaordfarmaciadesc + "," + lineaordfarmaciacant+ ","+ medicamentoid + ")";
        
        MySqlCommand comando = new MySqlCommand(consulta, conexion);
        try
        {
            conexion.Open();
            comando.ExecuteReader();
            conexion.Close();
            return "ok";
        }
        catch
        {
            return consulta;
        }
    }

    public static string deletelinaordfarmacia(string lineaordfarmaciaid)
    {   //elimina una linea de una orden de farmacia

        MySqlConnection conexion = Conexion.obtConexion();
        string consulta = @"DELETE FROM lineasordfarmacia
                            WHERE id=" + lineaordfarmaciaid;
        MySqlCommand comando = new MySqlCommand(consulta, conexion);
        try
        {
            conexion.Open();
            comando.ExecuteReader();
            conexion.Close();
            return "ok";
        }
        catch
        {
            return consulta;
        }
    }
    public static DataTable buscarlineaorfarmacia(string ordfarmaciaid)
    {   //busca las lineas correspondientes a una orden de farmacia

        MySqlConnection conexion = Conexion.obtConexion();
        DataTable tabla = new DataTable();
        string consulta = "select * from lineasordfarmacia where ordfarmaciaid='" + ordfarmaciaid + "'";
        MySqlCommand comando = new MySqlCommand(consulta, conexion);
        conexion.Open();
        MySqlDataReader data = comando.ExecuteReader();
        conexion.Close();
        tabla.Load(data, LoadOption.OverwriteChanges);
        return tabla;
    }



}
